﻿using HardcoreGame.Content.Items.Bosses.PumpkinBoy;
using HardcoreGame.Content.Items.Consumables.Bosses;
using HardcoreGame.Content.Items.Weapons.Sets.Heavy;
using HardcoreGame.Content.NPCs.Bosses.PB;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using Terraria.Localization;
using Terraria.ModLoader;

namespace HardcoreGame.Common.Systems
{
    public class ModIntegrationsSystem : ModSystem
    {
        public override void PostSetupContent()
        {
            DoBossChecklistIntegration();
        }
        private void DoBossChecklistIntegration()
        {

            if (ModLoader.TryGetMod("BossChecklist", out Mod bossChecklistMod) && bossChecklistMod.Version >= new Version(1, 6))
            {
                string internalName = "Boss";
                float weight = 1.1f;
                Func<bool> downed = () => DownedBossSystem.downedPumpkinBoy;
                int bossType = ModContent.NPCType<PumpkinBoy>();
                int spawnItem = ModContent.ItemType<PumpkinLantern>();
                var customPortrait = (SpriteBatch sb, Rectangle rect, Color color) =>
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/BCL/PumpkinBoy").Value;
                    Vector2 centered = new(rect.X + (rect.Width / 2) - (texture.Width / 2), rect.Y + (rect.Height / 2) - (texture.Height / 2));
                    sb.Draw(texture, centered, color);
                };
                List<int> collectibles =
            [
                ModContent.ItemType<PumpkinBoyTrophy>(),
                ModContent.ItemType<PumpkingMask>(),
                ModContent.ItemType<PumpkingBag>(),
                ModContent.ItemType<Reaper>(),
                ModContent.ItemType<PumpkingBoyRelic>(),
                ModContent.ItemType<Content.Items.Bosses.PumpkinBoy.PumpkinBomb>()
            ];
                bossChecklistMod.Call(
                    "LogBoss",
                    Mod,
                    internalName,
                    weight,
                    downed,
                    bossType,
                    new Dictionary<string, object>()
                    {
                        ["spawnInfo"] = Language.GetOrRegister("Mods.HardcoreGame.BossChecklist.PumpkinBoy"),
                        ["spawnItems"] = spawnItem,
                        ["collectibles"] = collectibles,
                        ["customPortrait"] = customPortrait
                    }
                );
            }
        }
    }
}
